   import 'package:flutter/material.dart';
   import 'package:date_format/date_format.dart';

class DatePickerPage extends StatefulWidget {
  DatePickerPage({Key key}) : super(key: key);

  @override
  _DatePickerPageState createState() => _DatePickerPageState();
}

class _DatePickerPageState extends State<DatePickerPage> {

  // var now = DateTime.now();

  DateTime _nowDate = DateTime.now();
  var _nowTime = TimeOfDay(hour: 12, minute: 20);

  _showDatePicker() async{

      // showDatePicker(
      //   context: context,
      //   initialDate: _nowTime,
      //   firstDate: DateTime(1980),
      //   lastDate: DateTime(2100),
      // ).then((value){
      //   print(value);
      // });

      var result = await showDatePicker(
        context: context,
        initialDate: _nowDate,
        firstDate: DateTime(1980),
        lastDate: DateTime(2100),
      );
      setState(() {
        this._nowDate = result;
      });
      print(result);
  }

  _showTimePicker() async{

      var result = await showTimePicker(
        context: context,
        initialTime: _nowTime
      );
      setState(() {
        this._nowTime = result;
      });
      print(result);
  }

  @override
    void initState() {
      // TODO: implement initState
      super.initState();
      // print(now); // 2021-06-19 10:21:06.723983
      // print(now.millisecondsSinceEpoch); // 1624067085664
      // print(DateTime.fromMillisecondsSinceEpoch(1624067085664)); // 2021-06-19 09:44:45.664
      // formatDate(DateTime.now(), [yyyy, '年', mm, '月', dd, '日']);
      print(formatDate(DateTime.now(), [yyyy, '年', mm, '月', dd, '日']));
    }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('datePicker'),
      ),
      body: Padding(
        padding: EdgeInsets.all(20),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Row(
              children: <Widget>[
                InkWell(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Text("${formatDate(this._nowDate, [yyyy, '年', mm , '月', dd, '日'])}"),
                      Icon(Icons.arrow_drop_down)
                    ],
                  ),
                  // onTap: (){
                  //   print(this._showDatePicker());
                  // },
                  onTap: _showDatePicker,
                ),
                InkWell(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Text("${_nowTime.format(context)}"),
                      Icon(Icons.arrow_drop_down)
                    ],
                  ),
                  // onTap: (){
                  //   print(this._showDatePicker());
                  // },
                  onTap: _showTimePicker,
                )
              ],
            )
          ],
        ),
      ),
    );
  }
}